<?php
// PHPViddlerUploadify
// Version 0.1
// By: Colin Devroe - cdevroe@viddler.com
// http://code.google.com/p/phpviddleruploadify/
// http://developers.viddler.com/

include_once('phpviddler.php');

class PhpviddlerUploadify extends Phpviddler {
	
	// Uploadify()
	// Creates the Browse button, the flash object for progress bar,
	// and the hidden field to store the video filename in.
	function Uploadify(
		$inputName='video',
		$multiUpload='false',
		$fileExt='*.mov;*.wmv;*.avi;*.mp4;*.m4v;*.divx;*.mpg;*.mpeg;*',
		$autoUpload='true',
		$uploadFolder='uploads') {
		
		$html = "<input type=\"file\" name=\"".$inputName."\" id=\"".$inputName."\" />\n" .
			"<script type=\"text/javascript\">\n" .
				"$(document).ready(function() {\n" .
				"$('#".$inputName."').fileUpload ({\n" .
				"'uploader'  : 'phpviddler/js/uploadify/uploader.swf',\n" .
				"'script'    : 'phpviddler/js/uploadify/upload.php',\n" .
				"'cancelImg' : 'phpviddler/js/uploadify/cancel.png',\n" .
				"'multi' 	: ".$multiUpload.",\n" .
				"'fileDesc'	: 'Please select a video file.',\n" .
				"'fileExt'	: '".$fileExt."',\n" .
				"'onComplete': function(evt, queueID, fileObj, response, data){\n" .
					"$('#completed').html('<p>Upload complete: '+fileObj.name+' ('+fileObj.size+' bytes)</p>');\n" .
					"$('#".$inputName."file').val(fileObj.name);\n".
				"},\n" .
				"'auto'      : ".$autoUpload.",\n" .
				"'folder'    : '".$uploadFolder."'\n" .
				"});\n" .
				"});\n" .
			"</script>\n" .
			"<input type=\"hidden\" name=\"videofile\" id=\"videofile\" class=\"required\" />\n";
			
			return $html;
	} // end Uploadify()
	
	// Uploads the Video to Viddler
	function UploadToViddler($sessionid,$title,$description,$tags,$public='1',$filelocation) {
		
		// Envoke standard PHPViddler upload
		$response = $this->video_upload(array(
			"sessionid" => $sessionid,
			"title" => addslashes($title),
			"tags" => $tags,
			"description" => addslashes($description),
			"make_public" => $public,
			"file" => "@".$filelocation
			));
			
		return $response;
	}

}


?>